package org.example.server.controller;

import com.google.zxing.WriterException;
import lombok.extern.slf4j.Slf4j;
import org.example.common.result.Result;
import org.example.dto.HospitalNoDDTO;
import org.example.dto.HospitalNoDTO;
import org.example.dto.PatientDTO;
import org.example.dto.PatientUDTO;
import org.example.server.service.PatientService;
import org.example.vo.AUPatientVO;
import org.example.vo.PatientDVO;
import org.example.vo.PatientVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/v1/patient")
public class PatientController {



    @Resource
    private PatientService patientService;

    @PostMapping("/simple/list")
    private Result<List<PatientVO>> getPatient(@RequestBody HospitalNoDTO hospitalNo) {
        log.info("患者列表查询");
        List<PatientVO> patientVOList = patientService.select(hospitalNo.getHospitalNo());
        return Result.success(patientVOList);
    }

    @PostMapping("/detail")
    private Result<PatientDVO> getPatientDetail(@RequestBody HospitalNoDDTO hospitalNoDDTO) throws IOException, WriterException {
log.info("患者详情查询");
        PatientDVO patientDVO = patientService.selectByD(hospitalNoDDTO);
        return Result.success(patientDVO);

    }

    @PostMapping("/add")
    private Result<AUPatientVO> addPatient(@RequestBody PatientDTO patientDTO) {
        log.info("患者新增");
        AUPatientVO AUPatientVO = patientService.insert(patientDTO);

        return Result.success(AUPatientVO);
    }

    @PostMapping("/edit")
    private Result<AUPatientVO> updatePatient(@RequestBody PatientUDTO patientUDTO) {
        log.info("患者编辑");
        patientService.update(patientUDTO);
        AUPatientVO auPatientVO = new AUPatientVO(patientUDTO.getPatientId());
        return Result.success(auPatientVO);
    }
}
